package com.wisemoresystem.seal.action.seal.destroy;

import java.util.List;
import java.util.Map;

import org.ne.framework.data.util.ChkTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_seal;
import com.wisemoresystem.seal.model.t_seal_destory;
import com.wisemoresystem.seal.model.t_seal_new;
import com.wisemoresystem.seal.model.t_seal_type_config;
import com.wisemoresystem.seal.service.SealDestroyService;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 印章销毁 销毁申请
 * 
 * @author hxj
 *
 */
@Controller("ixSealDestroy")
@Scope("prototype")
@RequestMapping("/ix/seal/destroy/destroy")
public class SealDestroyDestroyAction extends ProjBaseAction {

	@Autowired
	private SealDestroyService service;

	// t_seal flag_stop=上缴停用
	/**
	 * 印章销毁申请列表
	 * 
	 * @param srh_name
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String srh_name) {

		List<Map<String, Object>> list = service.selectSealDestroyList(
				WebTools.getCurrentBankId(), srh_name, page);

		ModelAndView mv = new ModelAndView("/jsp/seal/destroy/destroy/list");
		mv.addObject("list", list);
		return mv;
	}

	// 转到申请页面
	/**
	 * 转到申请页面
	 * 
	 * @param seal_id
	 *            印章id
	 * @return
	 */
	@RequestMapping("/destroy_form")
	public ModelAndView destroy_form(String seal_id) {

		t_seal seal = service.findObjById(seal_id, t_seal.class);

		ModelAndView mv = new ModelAndView(
				"/jsp/seal/destroy/destroy/destroy_form");
		mv.addObject("seal", seal);
		if (ChkTools.isNotNull(seal.getSeal_new_id())) {
			t_seal_new mac = service.findObjById(seal.getSeal_new_id(),
					t_seal_new.class);
			if (ChkTools.isNotNull(mac.getSeal_type_config_id())) {
				t_seal_type_config ma = service.findObjById(
						mac.getSeal_type_config_id(), t_seal_type_config.class);
				mv.addObject("ma", ma);
			}
			mv.addObject("mac", mac);
		}
		return mv;
	}

	// 申请
	/**
	 * 印章销毁申请
	 * 
	 * @param seal_id
	 *            印章id
	 * @param destroy
	 *            销毁信息
	 * @return
	 */
	@RequestMapping("/destroy")
	public ModelAndView destroy(String seal_id, t_seal_destory destroy) {

		if (service.apply(seal_id, destroy)) {
			super.setTipMsg("申请成功!", Tip.Type.success);
			logT.logH("印章销毁申请", t_seal.class, seal_id);
		} else {
			super.setTipMsg("申请失败!", Tip.Type.error);
		}

		ModelAndView mv = new ModelAndView("redirect:list.htm");
		return mv;
	}
}
